package mysql

import (
	"context"
	"go.uber.org/zap"
	"golang-sgg-daijia/internal/model"
)

type DriverLoginLogDao interface {
	Create(ctx context.Context, driverLog *model.DriverLoginLog) error
}

func NewDriverLoginLogDao(
	r *MysqlClient,
) DriverLoginLogDao {
	return &driverLoginLogDao{
		MysqlClient: r,
	}
}

type driverLoginLogDao struct {
	*MysqlClient
}

func (r *driverLoginLogDao) Create(ctx context.Context, driverLog *model.DriverLoginLog) error {
	if err := r.DB(ctx).Create(driverLog).Error; err != nil {
		r.logger.WithContext(ctx).Error("DriverLoginLogDao|Create(", zap.Any("data", map[string]interface{}{
			"DriverLog": *driverLog,
		}), zap.Error(err))
		return err
	}
	return nil
}
